<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<link rel="Bookmark" href="favicon.ico" >
	<link rel="Shortcut Icon" href="favicon.ico" />
	<!--[if lt IE 9]>
	<script type="text/javascript" src="/public/lib/html5.js"></script>
	<script type="text/javascript" src="/public/lib/respond.min.js"></script>
	<![endif]-->
	<link rel="stylesheet" type="text/css" href="/public/static/h-ui/css/H-ui.min.css?v=1.0" />
	<link rel="stylesheet" type="text/css" href="/public/static/h-ui.admin/css/H-ui.admin.css?v=1.0" />
	<link rel="stylesheet" type="text/css" href="/public/lib/Hui-iconfont/1.0.8/iconfont.css?v=1.0" />
	<link rel="stylesheet" type="text/css" href="/public/lib/Hui-iconfont/iconfont/iconfont.css?v=1.0" />
	<link rel="stylesheet" type="text/css" href="/public/static/h-ui.admin/skin/default/skin.css?v=1.0" id="skin" />
	<link rel="stylesheet" type="text/css" href="/public/static/h-ui.admin/css/style.css?v=1.0" />
	<script src="/public/menu/js/jquery-2.1.1.js"></script>
	<!--[if IE 6]>
	<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
	<script>DD_belatedPNG.fix('*');</script>
	<![endif]-->
	<title>洛阳易购商城</title>
	<meta name="keywords" content="洛阳易购商城">
	<meta name="description" content="洛阳易购商城">
</head>
<body>
<div class="Hui-article">
	<article class="cl pd-20">
		<div class="cl pd-5 bg-1 bk-gray mt-20">
			<span class="">
					<input name="file_upload" style="display: none" id="uploadImg" type="file" onchange="imgUpload(this,'{$ap_id}');">
					<input type="hidden" value="" id="adv_pic" />
				<a href="javascript:;" onclick="on_upload()" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe613;</i> 添加图片</a>
			</span>
		</div>
		<table class="table table-border table-bordered table-hover table-bg">
			<thead>
			<tr>
				<th scope="col" colspan="9">图片</th>
			</tr>
			<tr class="text-c">
				<th>排序</th>
				<th>图片标题</th>
				<th>链接</th>
				<th>宽度比例</th>
				<th>略缩图</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody>
			{volist name="img_list" id="vo"}
			<tr class="text-c">
				<td width="8">
					<input class="input-text" value="{$vo['sort']}" onchange="addsort(this.value,'{$vo.adv_id}');" onkeyup='this.value=this.value.replace(/\D/gi,"")' type="text" style="width: 50px;text-align: center" >
				</td>
				<td><input class="input-text" value="{$vo['adv_title']}" onchange="addtitle(this.value,'{$vo.adv_id}','title');" type="text" style="width: 150px;text-align: center" ></td>
				<td><input class="input-text" value="{$vo['adv_url']}" onchange="addtitle(this.value,'{$vo.adv_id}','url');" type="text" style="width: 150px;text-align: center" ></td>
				<td><input class="input-text" value="{$vo['adv_width']}" onchange="addtitle(this.value,'{$vo.adv_id}','width');" type="text" style="width: 50px;text-align: center" ><span style="font-size: 20px;">%</span></td>
				<td>
					<img width="60" class="product-thumb" src="/{$vo['adv_image']}">
				</td>
				<td>
					<a title="删除" href="javascript:;" onclick="advert_del(this,'{$vo.adv_id}')" class="ml-5" style="text-decoration:none"><i style="font-size: 20px" class="Hui-iconfont">&#xe6e2;</i></a>
				</td>
			</tr>
			{/volist}
			</tbody>
		</table>
	</article>
	<div class="n_page_no">
	</div>
</div>
<script type="text/javascript" src="/public/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/public/static/h-ui/js/H-ui.js"></script>
<script src="/public/static/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="/public/static/js/file_upload.js" type="text/javascript"></script>
<script type="text/javascript">
    function on_upload() {
        $("#uploadImg").click();
    }
    //图片上传
    function imgUpload(event,ap_id) {
        var fileid = $(event).attr("id");
        var str = $(event).next().attr("id");
        var data = { 'file_path' : "adv/" };
        uploadFile(fileid,data,function(res){
            if(res.code){
                //$("#img"+str).attr("src","__ROOT__/"+res.data);
                //$("#"+str).val(res.data);
                $.ajax({
                    type : "post",
                    url : "{:url('advert/AddAdvertPosImg')}",
                    data : {
                        'adv_img' : res.data,
                        'ap_id' : ap_id,
                    },
                    success : function(data) {
                        if(data['code']>0){
                            layer.msg('添加成功!',{icon:1,time:1000},function () {
                                window.location.reload();
                            });
                        }
                        else{
                            layer.msg(data['message'],{icon:5,time:1000});
                        }
                    }
                });
            }else{
                layer.msg(res.message,{icon:1,time:1000});
            }
        });
    }
    /**
	 * 图片排序
     * @param val
     * @param adv_id
     */
    function addsort(val,adv_id) {
        $.ajax({
            type : "post",
            url : "{:url('advert/AdvertPositionSort')}",
            data : {
                "sort" : val,
                "adv_id" : adv_id,
            },
            success : function(data) {
                if (data['code'] > 0) {
                    layer.msg(data['message'],{icon:1,time:1000},function () {
                        window.location.reload();
                    });
                }else{
                    layer.msg(data['message'], {icon: 2, time: 1000});
                }
            }
        })
    }
    /**
     * 图片标题
     * @param val
     * @param adv_id
     */
    function addtitle(val,adv_id,key) {
        $.ajax({
            type : "post",
            url : "{:url('advert/AdvertImg')}",
            data : {
                "adv_title" : val,
                "adv_id" : adv_id,
                "key" : key,
            },
            success : function(data) {
                if (data['code'] > 0) {
                    layer.msg(data['message'],{icon:1,time:1000},function () {
                        window.location.reload();
                    });
                }else{
                    layer.msg(data['message'], {icon: 2, time: 1000});
                }
            }
        })
    }
    function advert_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            //此处请求后台程序，下方是成功后的后台处理……
            //删除
            $.ajax({
                type : "post",
                url : "{:url('advert/delAdvert')}",
                data : {
                    "adv_id" : id,
                },
                success : function(data) {
                    if (data['code'] > 0) {
                        $(obj).parents("tr").remove();
                        layer.msg(data['message'],{icon:1,time:1000});
                    }else{
                        layer.msg(data['message'], {icon: 2, time: 1000});
                    }
                }
            })
        });
    }
</script>
</body>
</html>